<%--
  Created by IntelliJ IDEA.
  User: 平步青云
  Date: 2021/4/14
  Time: 16:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <base href="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/"/>
    <script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="layer/layer.js
"></script>
</head>
<body>
<a href="test/ssm.html">测试SSM整合环境</a>

<br/>
<button>Test Request Body</button>
<button id="btn1">Send [5,8,12] One</button>
<button id="btn2">Send [5,8,12] Two</button>
<button id="btn3">Send Student three</button>
<br/>
<button id="btn4">点击弹框</button>
<button id="btn5"><a href="/webui/admin/to/login/page.html">登录页面</a></button>
<script>
    $(function(){
        $("#btn1").click(function (){
            $.ajax({
                "url":"send/One.html",    //请求目标资源地址
                "type":"post",              //请求方式
                "data":{
                    "array":[5,8,12]
                },            //要发送的请求参数
                "dataTyoe":"text",          //如何对待服务器端返回的数据
                "success":function(response){   //服务器端成功处理请求后调用的回调函数
                    alert(response);
                },
                "error":function (response){    //服务器端处理请求失败后调用的回调函数
                    alert(response);
                }
            });
        });
        $("#btn2").click(function (){
            //准备发送到服务器的数组
            var array = [1,2,3];
            console.log(array.length);
            //将JSON数组转换为JSON字符串
            var requestBody = JSON.stringify(array);
            //"['5','8','12']"
            console.log(requestBody.length)
            $.ajax({
                "url":"send/Two.html",    //请求目标资源地址
                "type":"post",              //请求方式
                "data":requestBody,
                "contentType":"application/json;charset=UTF-8",//设置请求体的内容类型,告诉服务器端是json数据
                "dataTyoe":"text",          //如何对待服务器端返回的数据
                "success":function(response){   //服务器端成功处理请求后调用的回调函数
                    alert(response);
                },
                "error":function (response){    //服务器端处理请求失败后调用的回调函数
                    alert(response);
                }
            });
        });
        $("#btn3").click(function (){
           var student = {
                "stuId" : 1,
                "stuName": "Tom",
                "address" : {
                    "province" :"山东",
                    "city":"临沂",
                   "street":"保安大队"
               },
                "subject":[{
                    "subjectName":"javase",
                    "subjectScore":100
                },{
                    "subjectName":"SSM",
                    "subjectScore":99
                }
                ],
               "map":{
                    "k1":"v1",
                   "k2":"v2"
               }
           };
           var requestBody = JSON.stringify(student)
           $.ajax({
               "url":"send/Three.json",
               "type":"post",
               "data":requestBody,
               "contentType":"application/json;charset=UTF-8",
               "dataType":"json",
               "success":function(response){
                console.log(response);
               },
               "error":function(response){
                alert(response);
               }
           });
        });
        $("#btn4").click(function(){
          // alert("aaa....s");
           layer.msg("123456")
        });
      })
</script>
</body>
</html>
